package com.tjsinfo.tjsoa.documentationflow.xingzhengshouwen.action;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.json.JSONArray;
import org.json.JSONObject;

import com.tjsinfo.tjsoa.common.SessionUser;
import com.tjsinfo.tjsoa.common.ToolKit;
import com.tjsinfo.tjsoa.system.bo.ISystemUserRoleBO;
import com.tjsinfo.tjsoa.system.bo.ITjsRolesBo;
import com.tjsinfo.tjsoa.system.vo.TjsRoles;



public class IsDengJiAction extends Action{
	
	private ITjsRolesBo tjsRolesBo;
	private ISystemUserRoleBO systemUserRoleBO;
	
	public ISystemUserRoleBO getSystemUserRoleBO() {
		return systemUserRoleBO;
	}

	public void setSystemUserRoleBO(ISystemUserRoleBO systemUserRoleBO) {
		this.systemUserRoleBO = systemUserRoleBO;
	}

	public ITjsRolesBo getTjsRolesBo() {
		return tjsRolesBo;
	}

	public void setTjsRolesBo(ITjsRolesBo tjsRolesBo) {
		this.tjsRolesBo = tjsRolesBo;
	}
	@Override
	public ActionForward execute(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		// TODO Auto-generated method stub
		String rolesname = ToolKit.getProperties("com/tjsinfo/tjsoa/documentationflow/xingzhengshouwen/properties/systemResource.properties", this).
		getProperty("xingzhengshouwen.dengji");
		Integer id =  SessionUser.getUserId(request);
		List<TjsRoles> list = tjsRolesBo.selectRolesByName(rolesname);
		if (list.size() > 0) {
			TjsRoles tjsRoles = list.get(0);
			JSONArray array = new JSONArray();
			JSONObject object = new JSONObject();
			if (systemUserRoleBO.selectUserRoleByUserId(tjsRoles.getId(), id)) {
					object.put("success", true);
			} else {
					object.put("success", false);	
			}
			array.put(object);			
			response.getWriter().print(array);
		} else {
			JSONArray array = new JSONArray();
			JSONObject object = new JSONObject();
			object.put("success", false);	
			array.put(object);			
			response.getWriter().print(array);
		}
		return null;
	}
	
}
